package com.OrderingServer.service.impl;

import com.OrderingServer.mapper.ProductCategoryMapper;
import com.OrderingServer.pojo.ProductCategory;
import com.OrderingServer.service.ProductCategoryService;
import com.OrderingServer.utils.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ProductCategoryServiceimpl extends ServiceImpl<ProductCategoryMapper, ProductCategory> implements ProductCategoryService {
    private final ProductCategoryMapper productCategoryMapper;

    public ProductCategoryServiceimpl(ProductCategoryMapper productCategoryMapper) {
        this.productCategoryMapper = productCategoryMapper;
    }

    //分页
    @Override
    public PageInfo<ProductCategory> selectPage(Integer pageNum, Integer pageSize, ProductCategory productCategory) {
       //设置分页插件
        PageHelper.startPage(pageNum, pageSize);
        //正常查询，查询数据
        QueryWrapper<ProductCategory> queryWrapper = new QueryWrapper<ProductCategory>();
        queryWrapper.like(true,"category_name",productCategory.getCategoryName());
        queryWrapper.eq("del","0");//未删除
        List<ProductCategory> list = productCategoryMapper.selectList(queryWrapper);
        return PageInfo.of(list);
    }

    @Override
    public List<ProductCategory> findAllByDel() {
        return productCategoryMapper.findAllByDel();
    }

}
